//
//  PlayCentreView.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2018/12/26.
//  Copyright © 2018 Gox_WallyDiao. All rights reserved.
//

import UIKit
protocol PlayCentreViewDelegate:NSObjectProtocol {
    func playCentreViewAction(state:Int)
}

class PlayCentreView: UIView {
    
    weak var delegate:PlayCentreViewDelegate?
    lazy var leftBtn:UIButton = {
        let button = UIButton(type: UIButton.ButtonType.custom)
        button.frame = FRAME_CGFloat(0, 0, SCREEN_WIDTH / 3, 34)
        button.setTitle("节目介绍", for: .normal)
        button.addTarget(self, action: #selector(btnAction(btn:)), for: .touchUpInside)
        button.setTitleColor(RGB_Same(53), for: .normal)
        button.titleLabel?.font = Font_Medium(14)
        button.tag = 11
        return button
    }()
    
    lazy var centerBtn:UIButton = {
        let button = UIButton(type: UIButton.ButtonType.custom)
        button.frame = FRAME_CGFloat(SCREEN_WIDTH / 3, 0, SCREEN_WIDTH / 3, 34)
        button.setTitle("节目选集", for: .normal)
        button.addTarget(self, action: #selector(btnAction(btn:)), for: .touchUpInside)
        button.setTitleColor(RGB_Same(53), for: .normal)
        button.titleLabel?.font = Font_Medium(14)
        button.tag = 12
        return button
    }()
    
    lazy var rightBtn:UIButton = {
        let button = UIButton(type: UIButton.ButtonType.custom)
        button.frame = FRAME_CGFloat(SCREEN_WIDTH * 2 / 3, 0, SCREEN_WIDTH / 3, 34)
        button.setTitle("精选评论", for: .normal)
        button.addTarget(self, action: #selector(btnAction(btn:)), for: .touchUpInside)
        button.setTitleColor(RGB_Same(53), for: .normal)
        button.titleLabel?.font = Font_Medium(14)
        button.tag = 13
        return button
    }()
    
    var leftView:UIView = {
        let view = UIView.init(frame: FRAME_CGFloat(SCREEN_WIDTH / 6 - 8, 31, 16, 3))
        view.backgroundColor = BlackBackColor
        return view
    }()
    
    var centerView:UIView = {
        let view = UIView.init(frame: FRAME_CGFloat(SCREEN_WIDTH / 2 - 8, 31, 16, 3))
        view.backgroundColor = BlackBackColor
        return view
    }()
    
    var rightView:UIView = {
        let view = UIView.init(frame: FRAME_CGFloat(SCREEN_WIDTH * 5 / 6 - 8, 31, 16, 3))
        view.backgroundColor = BlackBackColor
        return view
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        self.backgroundColor = RGB_Same(243)
        
        self.addSubview(self.leftBtn)
        self.addSubview(self.centerBtn)
        self.addSubview(self.rightBtn)
        self.addSubview(self.leftView)
        self.addSubview(self.centerView)
        self.addSubview(self.rightView)
        
    }
    
    @objc func btnAction(btn: UIButton) {
        if btn.tag == 11{
            showLeft()
        } else if btn.tag == 12 {
            showCenter()
        } else if btn.tag == 13 {
            showRight()
        }
        delegate?.playCentreViewAction(state: btn.tag)
        
    }
    
    func btnTag(tag:Int) {
        if tag == 11{
            showLeft()
        } else if tag == 12 {
            showCenter()
        } else if tag == 13 {
            showRight()
        }
    }
    
    func showLeft() {
        self.leftView.isHidden = false
        self.centerView.isHidden = true
        self.rightView.isHidden = true
    }
    
    func showRight() {
        self.leftView.isHidden = true
        self.centerView.isHidden = true
        self.rightView.isHidden = false
    }
    
    func showCenter() {
        self.leftView.isHidden = true
        self.centerView.isHidden = false
        self.rightView.isHidden = true
    }
}
